<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
[#include "/admin/include/head.htm"]
<script type="text/javascript">
	//删除门店
	function deleteStore(){
      	jQuery.ligerDialog.confirm('确定删除吗?', function (confirm) {
      		if (confirm){
				LG.ajax({
					url: "delete.jhtml",
					data: {"ids": $("#dept_id").val()},
					success: function(result){
						LG.showSuccess("删除门店成功!");
						window.parent.leftFrame.removeNode(result.id);
						if(result.parentId){
							window.location.href="add.jhtml?dept_id=" + result.parentId;
						}else{
							window.location.href="add.jhtml";
						}				
					},			
		             error: function (message) {
		                  LG.showError(message);
		              }
				});
			}
		});
	}
	
	//添加门店
	function add(){
		LG.submitForm($("#childForm"), function(data){
			window.parent.leftFrame.addNode(data, false);
			LG.showSuccess("添加门店成功!");
			$("#childForm").clearForm();
		});
	}
	
	//编辑门店
	function edit(){
		LG.submitForm($("#currentStore"), function(data){
			window.parent.leftFrame.updateNode(data);
			LG.showSuccess("修改门店成功!");
			$("#currentStore").clearForm();
		});
	}
</script>
</head>
[#if store??]
	[#assign isAdd = true /]
[#else]
	[#assign isEdit = true /]
[/#if]
<body>
<div class="body-box">
[#if isAdd??]
	<div class="currentStore">
		<div class="table_title">
			<img src="${base}/resource/images/communication.gif" />
			<span>修改门店信息 </span>
		</div>
		<form action="update.jhtml" method="post" id="currentStore" class="validate">
			<table class="table">
				<tr>
					<th>上级门店:</th>
					<td>
						[#if store??&&store.upDomain??]
							${(store.upDomain.name)!''}
						[#else]
							${(store.genRoot().name)!''}
						[/#if]
					</td>
				</tr>
				<tr>
					<th>门店编码:</th>
					<td><input type="text" class="formText {required: true,remote: 'checkCode.jhtml?oldValue=${(store.code)!''}',maxlength:12, minlength:2, messages:{remote: '门店编号不能重复!'}}" 
						name="code" value="${(store.code)!''}"/></td>
				</tr>
				<tr>
					<th>门店名称:</th>
					<td><input type="text" class="formText {required: true,maxlength:12,minlength:2}" value="${(store.name)!''}" 
						name="name"/>
						<input type="hidden" name="id" value="${(store.id)!''}" id="dept_id"/>	
					</td>
				</tr>
				<tr>
                <tr>
                    <th>所属城市：</th>
                    <td>
						[@u.select_map headerKey="" headerValue="请选择" listKey="id" listValue="name" value="${(store.city.id)!''}" list=citys  name="city.id"/]
                    </td>
                </tr>
				<tr>
					<th>联系人:</th>
					<td><input type="text" class="formText {maxlength:12,minlength:2}" value="${(store.contact)!''}" name="contact"/></td>
				</tr>
				<tr>
					<th>联系电话:</th>
					<td><input type="text" class="formText {mobileOrTelephone:true}" value="${(store.telephone)!''}" name="telephone"/></td>
				</tr>
				<tr>
					<th>排序:</th>
					<td><input type="text" class="formText {digits:true}" value="${(store.priority)!''}" name="priority"/></td>
				</tr>
				<tr>
					<th></th>
					<td>
						[#if !update?? || update]
							<input type="button" class="button" value="保存" onclick="edit();"/>
						[/#if]
						[#if !delete?? || delete]
							<input type="button" class="button" value="删除" onclick="deleteStore();"/>
						[/#if]
					</td>
				</tr>
			</table>
		</form>
	</div>
[/#if]
[#if !add?? || add]
<div class="childChild">
	<div class="table_title">
		<img src="${base}/resource/images/communication.gif" />
		<span>添加下属门店 </span>
	</div>
	<form action="save.jhtml" method="post" id="childForm" class="validate">
		[#if store?? && store.id??]
			<input type="hidden" name="upDomain.id" value="${(store.id)!''}"/>
		[/#if]
		
		<table class="table">
			<tr>
				<th>门店编码:</th>
				<td><input type="text" class="formText {required: true,remote: 'checkCode.jhtml?oldValue=${(store.code)!''}', maxlength:12, minlength:2, messages:{remote: '门店编号不能重复!'}}" 
					name="code" value="${(store.code)!'001'}"/></td>
			</tr>
			<tr>
				<th>门店名称:</th>
				<td><input type="text" class="formText {required: true,maxlength:12,minlength:2}" name="name"/></td>
			</tr>
            <tr>
                <th>所属城市：</th>
                <td>
					[@u.select_map headerKey="" headerValue="请选择" listKey="id" listValue="name" list=citys  name="city.id"/]
                </td>
            </tr>
			<tr>
				<th>联系人:</th>
				<td><input type="text" class="formText {maxlength:12,minlength:2}" value="" name="contact"/></td>
			</tr>
			<tr>
				<th>联系电话:</th>
				<td><input type="text" class="formText  {digits:true}" value="" name="telephone"/></td>
			</tr>
			<tr>
				<th>排序:</th>
				<td><input type="text" class="formText  {digits:true}" value="" name="priority"/></td>
			</tr>
			<tr>
				<th></th>
				<td><input type="button" class="button" value="添加" onclick="add();"/></td>
			</tr>
		</table>
	</form>
</div>
[/#if]
</div>
</body>
</html>